﻿using System;
using System.Windows.Forms;
using TShooter.TfsSearch.ProtocolHandler.Core;

namespace TShooter.TfsSearch.ProtocolHandler
{
    static class Program
    {

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            TfsUrl url;

            if (!ProcessCommandLine(out url))
            {
                Environment.ExitCode = 1;
                return;
            }

            OpenUrl(url);
        }

        private static bool ProcessCommandLine(out TfsUrl url)
        {
            string[] args = Environment.GetCommandLineArgs();

            if (args.Length != 2)
            {
                url = null;
                return false;
            }

            try
            {
                url = new TfsUrl(args[1]);
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Error parsing URL {0}\n\n{1}", args[1], ex.Message), 
                    Application.ProductName,
                    MessageBoxButtons.OK, 
                    MessageBoxIcon.Error);
                url = null;
                return false;
            }

            return true;
        }

        private static void OpenUrl(TfsUrl url)
        {

        }
    }
}
